package ru.btabank.dom.xpath.expression;

import java.util.ArrayList;

import ru.btabank.dom.xpath.XPathException;

public abstract class FunctionCall extends Expression {
    private ArrayList parameters;

    public FunctionCall() {
        this.parameters = new ArrayList(4);
    }

    public void addParameter(Expression expression) {
        this.parameters.add(expression);
    }

    private int getParametersCount() {
        return this.parameters.size();
    }

    private Expression getParameter(int position) {
        return (Expression)parameters.get(position);
    }

    protected ArrayList evaluateValues(NodeSet context) throws XPathException {
        ArrayList values;
        Expression parameter;

        values = new ArrayList(4);
        for (int index = 0; index < this.getParametersCount(); index++) {
            parameter = this.getParameter(index);
            values.add(parameter.evaluate(context));
        }
        return values;
    }
}
